package com.jml.controller;

import com.jml.entity.JmlUser;
import com.jml.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class UserController {
    @Autowired
    private UserMapper jmlUserMapper;


    /**
     * 查询所有
     *
     * @return
     */
    @RequestMapping("/userList")
    public List<JmlUser> userList() {
        return jmlUserMapper.userList();
    }

    /**
     * 分页查询
     *
     * @return
     */
    @RequestMapping("/userListPage")
    public List<JmlUser> userListPage() {
        return jmlUserMapper.userListPage();
    }

    /**
     * 排序
     *
     * @return
     */
    @RequestMapping("/userOrderBy")
    public List<JmlUser> userOrderBy() {
        return jmlUserMapper.userOrderBy();
    }

    @RequestMapping("/getByUserId")
    public List<JmlUser> getByUserId(Long id) {
        return jmlUserMapper.getByUserId(id);
    }

    @RequestMapping("/insertUser")
    public String insertUser() {
        for (int i = 1; i < 10; i++) {
            JmlUser jmlUser = new JmlUser(i, "jml" + i, i);
            try {
                jmlUserMapper.insert(jmlUser);
            } catch (Exception e) {

            }
        }
        return "success";
    }
}
